/**
 * yvanui.window
 * @author luoyifan
 * 2019-07-08 23:07:00
 */
"use strict";
(function () {

  if (!$.yvan) {
    console.error('$.yvan not loading');
    return;
  }

  $.yvan.component = $.yvan.component || {};

  $.extend($.yvan.component, {

    searchbox: function ($targetDOM, context, option) {
      if ($.yvan.beforeRender.call(this, $targetDOM, context, option) === false) {
        return;
      }

      var $dom = $(
        '<div yvan="searchbox">' +
        '  <input type="text"/>' +
        '  <div class="search"><i class="fa fa-search" style="margin-top: 4px;"></i></div>\n' +
        '</div>');
      $targetDOM.append($dom);

      delete option.component;

      $dom.jqxInput(option);
      $dom.find('.search')
        .on('click', function () {
          var value = $dom.find('input').val();
          alert("Searching for: " + value);
        });

      $.yvan.afterRender.call($dom[0], $targetDOM, context, option);
      return $dom;
    },

    form: function ($targetDOM, context, option) {
      if ($.yvan.beforeRender.call(this, $targetDOM, context, option) === false) {
        return;
      }

      var $dom = $('<div yvan="form"></div>');
      $targetDOM.append($dom);

      $dom.jqxForm({
        template: option.items,
        padding: { left: 10, top: 10, right: 10, bottom: 10 }
      });

      $.yvan.afterRender.call($dom[0], $targetDOM, context, option);
      return $dom;
    }
  });

})(jQuery);